import { ref } from 'vue'
import axios from "axios";

interface Comments {
    name: string;
    url: string;
    picurl: string;
    artistsname: string;
    avatarurl: string;
    nickname: string;
    content: string;

}


export function useUomg() {


    const tableData = ref<Comments[]>([])




    async function queryComment() {
        //网络请求
        const url = "https://api.uomg.com/api/comments.163?format=json"

        // console.log('1 准备请求网络')

        //get  请求 异步

        // const p = axios.get(url);

        // console.log(
        //   '%c p : ',
        //   'background-color: #3756d4; padding: 4px 8px; border-radius: 2px; font-size: 14px; color: #fff; font-weight: 700;',
        //   p  
        // )

        // p.then(res=>{
        //     console.log("2 then   .....");

        //     const data = res.data.data

        //     tableData.value.push(data)
        // })

        // console.log("3 返回结果") //接收结果



        console.log('1 准备请求网络')
        const res = await axios.get(url)

        console.log("2 返回结果   .....");
        const data = res.data.data

        console.log("3 处理结果  .....");
        tableData.value.push(data)




    }


    return {
        tableData,
        queryComment
    }

}

